package logic.SysPerson

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.ad.domain.SysPerson
import cn.ibizlab.core.ad.service.SysPersonService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  用户组下添加用户
 */
class GoupAddPerson {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //连接名称
        if(true) {
            rawsqlcall1()
        }
    }

    //直接SQL调用
    def rawsqlcall1() {
        Map param =new HashMap();
        param.put("param0",_default.get("srfparentkey"));
        String strSql="""
    select 
CONCAT_WS('','[',GROUP_CONCAT(CONCAT_WS('','{organizational_role_name: "',t.`NAME`,'",organizational_role_id: "',t.`ID`,'"}')), ']') as member_of  from 
sys_organizational_role t 
where t.ENABLED = 1 and t.ID = #{et.param0}
        """
        java.util.List<JSONObject> entities = SpringContextHolder.getBean(SysPersonService.class).select(strSql,param);//SQL调用
        if(entities.size()>0 && !ObjectUtils.isEmpty(entities.get(0))){
            JSONObject entity = entities.get(0);
            for (Map.Entry entry : entity.entrySet()) {
                _default.set(String.valueOf(entry.getKey()),entry.getValue());
            }
        }

    }

}
